package com.bdqn.action;

import com.bdqn.pojo.User;
import com.opensymphony.xwork2.Action;
import org.apache.struts2.ServletActionContext;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

public class UserAction implements Action {


    /*private String username;
    private String password;

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
*/

    private User user;

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    /* 登录 */
    @Override
    public String execute() throws Exception {
        if(user != null){
            if("admin".equals(user.getUsername()) && "admin".equals(user.getPassword())){

                /*HttpRequest request= */
                HttpServletRequest request = ServletActionContext.getRequest();
                HttpSession session = request.getSession();
                session.setAttribute("username",user.getUsername());
                return "success";
            } else {
                return "fail";
            }
        } else {
            return "fail";
        }

    }
}
